/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgBattleScene
    {
        private readonly Dictionary<int, CfgBattleScene> _dataMap;
        private readonly List<CfgBattleScene> _dataList;


        public TbCfgBattleScene(ByteBuf _buf)
        {
            //first read common data
            _TbCommonBattleScene _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonBattleScene(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgBattleScene>(size * 3 / 2);
            _dataList = new List<CfgBattleScene>(size);

            for (int i = 0; i < size; i++)
            {
                CfgBattleScene _v;
                _v = CfgBattleScene.DeserializeCfgBattleScene(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgBattleScene> DataMap => _dataMap;
        public IReadOnlyList<CfgBattleScene> DataList => _dataList;

        public CfgBattleScene Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgBattleScene] config not found,id:" + key.ToString());

            return null;
        }

        public CfgBattleScene GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "battlescene";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgBattleScene LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgBattleScene(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgBattleScene
    {
        private CfgBattleScene(ByteBuf _buf, _TbCommonBattleScene _commonData)
        {
            Id = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; BattleSceneFile = _commonData._field0[dataIndex]; }
            BattleRadius = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; PlayerBorn = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; MonsterBorn = _commonData._field2[dataIndex]; }

            PostInit();
        }

        internal static CfgBattleScene DeserializeCfgBattleScene(ByteBuf _buf, _TbCommonBattleScene _commonData)
        {
            return new CfgBattleScene(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 场景文件名
        /// </summary>
        public string BattleSceneFile { get; private set; }
        /// <summary>
        /// 地图半径mm
        /// </summary>
        public int BattleRadius { get; private set; }
        /// <summary>
        /// 玩家出生点
        /// </summary>
        public IReadOnlyList<IReadOnlyList<float>> PlayerBorn { get; private set; }
        /// <summary>
        /// 怪物出生点1
        /// </summary>
        public IReadOnlyList<IReadOnlyList<float>> MonsterBorn { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonBattleScene
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<IReadOnlyList<float>>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<IReadOnlyList<float>>> _field2 { get; private set; }
        internal _TbCommonBattleScene(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new float[__n0][][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ float[][] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new float[__n1][]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ float[] __v1; { int __n2 = _buf.ReadSize(); var __f2 = new float[__n2]; __v1 = __f2; for (var __i2 = 0 ; __i2 < __n2 ; __i2++ ){ float __v2; __v2 = _buf.ReadFloat(); __f2[__i2] = __v2;} } __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new float[__n0][][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ float[][] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new float[__n1][]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ float[] __v1; { int __n2 = _buf.ReadSize(); var __f2 = new float[__n2]; __v1 = __f2; for (var __i2 = 0 ; __i2 < __n2 ; __i2++ ){ float __v2; __v2 = _buf.ReadFloat(); __f2[__i2] = __v2;} } __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
